package com.zhugang.week13.stack;

/**
 * @program algorithms
 * @description: StackByArray
 * @author: chanzhugang
 * @create: 2022/11/01 11:03
 */
public class StackByArray {

    private int[] items;
    /**
     * 元素个数
     */
    private int count;
    /**
     * 栈的大小
     */
    private int n;


    /**
     * 入栈
     *
     * @param item
     * @return
     */
    public boolean push(int item) {
        if (count == n) {
            return false;
        }
        items[count] = item;
        count++;
        return true;
    }

    /**
     * 出栈
     *
     * @return
     */
    public int pop() {
        if (count == 0) {
            return -1;
        }
        int item = items[count];
        count--;
        return item;
    }

    /**
     * 查询栈顶元素
     *
     * @return
     */
    public int peek() {
        if (count == 0) {
            return -1;
        }
        return items[count];
    }

}